﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// AOE 技能
class SkillLogicAOE : SkillLogicBase
{
    protected override void initTimeLine()
    {
        _timeLine.AddEvent(0, 0, onSkillStart);
        _timeLine.AddEvent(0, 12, onAni); // 播动画
        // 播放粒子特效
        _timeLine.AddEvent(0.42192f, 1, onParticle);
        // 生成结算物
        _timeLine.AddEvent(0.42192f, 1, onCalcObject);
        // 恢复到idle状态
        _timeLine.AddEvent(1.0f, 12, onAniEnd);
        // 音效
        _timeLine.AddEvent(1.0f, 0, onSkillEnd);
    }

    private void onCalcObject(int __null)
    {
        //var obj = new GameObject("CapsuleCalc");
        //obj.AddComponent<CalcObject>();

        var retList = Physics.CapsuleCastAll(Vector3.up * -10, Vector3.up * 10, 10, Vector3.up, 0);

        List<Creature> hitList = new List<Creature>();
        foreach (var ret in retList)
        {
            var creature = ret.transform.GetComponent<Creature>();
            if (creature != null && creature.CanBeAttack(_owner))
            {
                hitList.Add(creature);
            }
        }

        onSkillHit(hitList);
    }

    private void onSkillHit(List<Creature> hitList)
    {
        DamageMgr.Instance.PhysicsDamage(_owner, hitList, _skillObject);
    }

}

